﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BuildHouse
{
    public partial class Form1 : Form
    {
        private Location _currentLocation;

        private RoomWithDoor _livingRoom;

        private Room _diningRoom;

        private RoomWithDoor _kitchen;

        private OutsideWithDoor _frontYard;

        private OutsideWithDoor _backYard;

        private Outside _garden;

        public Form1()
        {
            InitializeComponent();
            CreateObjects();
            MoveToANewLocation(_livingRoom);
        }

        private void CreateObjects()
        {
            _livingRoom = new RoomWithDoor("Living Room", "an antique carpet", "an oak door with a brass knob");
            _diningRoom = new Room("Dining Room", "a crystal chandelier");
            _kitchen = new RoomWithDoor("Kitchen", "stainless steel appliances", "a screen door");
            _frontYard = new OutsideWithDoor("Front Yard", false, "an oak door with a brass knob");
            _backYard = new OutsideWithDoor("Back Yard", true, "a screen door");
            _garden = new Outside("Garden", false);

            _diningRoom.Exits=new Location[]{_livingRoom,_kitchen};
            _livingRoom.Exits=new Location[]{_diningRoom};
            _kitchen.Exits=new Location[]{_diningRoom};
            _frontYard.Exits=new Location[]{_backYard,_garden};
            _backYard.Exits=new Location[]{_frontYard,_garden};
            _garden.Exits=new Location[]{_backYard,_frontYard};

            _livingRoom.DoorLocation = _frontYard;
            _frontYard.DoorLocation = _livingRoom;
            _kitchen.DoorLocation = _backYard;
            _backYard.DoorLocation = _kitchen;
        }

        private void MoveToANewLocation(Location newLocation)
        {
            _currentLocation = newLocation;
            CboExits.Items.Clear();
            foreach (var exit in newLocation.Exits)
            {
                CboExits.Items.Add(exit.Name);
            }
            CboExits.SelectedIndex = 0;

            TxtDescription.Text = _currentLocation.Description;
            if (_currentLocation is IHasExteriorDoor)
            {
                BtnGoThroughTheDoor.Visible = true;
            }
            else
            {
                BtnGoThroughTheDoor.Visible = false;
            }
        }

        private void BtnGoHere_Click(object sender, EventArgs e)
        {
            MoveToANewLocation(_currentLocation.Exits[CboExits.SelectedIndex]);
            ;
        }

        private void BtnGoThroughTheDoor_Click(object sender, EventArgs e)
        {
            var hasDoor = _currentLocation as IHasExteriorDoor;
            if (hasDoor != null)
            {
                MoveToANewLocation(hasDoor.DoorLocation);
            }
        }
    }
}
